#
# @lc app=leetcode.cn id=7 lang=python3
#
# [7] 整数反转
#

# @lc code=start
class Solution:
    def reverse(self, x: int) -> int:
        nativeTag = False
        if x < 0:
            x = - x
            nativeTag = True
        reserveNumber = 0
        while x != 0:
            endNumber = x % 10
            x = x // 10
            reserveNumber = reserveNumber * 10 + endNumber
        if nativeTag:
            reserveNumber = - reserveNumber
        
        if reserveNumber >= -2**31 and reserveNumber <= 2**31 -1:
            return reserveNumber
        else:
            return 0    
# @lc code=end